import { query } from '../config/database.js'

export const createRoundTypesTable = async () => {
  const sql = `
    CREATE TABLE IF NOT EXISTS round_types (
      id INT AUTO_INCREMENT PRIMARY KEY,
      name VARCHAR(50) NOT NULL,
      description TEXT,
      created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
      updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    )
  `
  
  try {
    await query(sql)
    console.log('Round types table created or already exists')
  } catch (error) {
    console.error('Error creating round types table:', error)
    throw error
  }
}

export const createRoundType = async (name, description) => {
  const sql = 'INSERT INTO round_types (name, description) VALUES (?, ?)'
  try {
    const result = await query(sql, [name, description])
    return result.insertId
  } catch (error) {
    console.error('Error creating round type:', error)
    throw error
  }
}

export const getAllRoundTypes = async () => {
  const sql = 'SELECT * FROM round_types ORDER BY id'
  try {
    return await query(sql)
  } catch (error) {
    console.error('Error getting round types:', error)
    throw error
  }
} 